﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Seating.utils;
using Sugar.Enties;

namespace Seating
{
    public partial class Library_Chose_Form : Form
    {
        public Library_Chose_Form()
        {
            InitializeComponent();
        }

        private Button buildNewLibrary(string name, int line, int row, int width, ref Color color, ref Color bgColor, Font font, string libraryId, int space)
        {
            Button btn = new Button();
            btn.Name = name;
            btn.Text = name;
            btn.ForeColor = color;
            btn.BackColor = bgColor;
            btn.Font = font;
            btn.Width = width;
            btn.Height = width;
            btn.Location = calcLocation(line, row, width, space);

            btn.Click += (s, arg) =>
            {
                choseLibrary(libraryId);
            };
            return btn;
        }

        private static Point calcLocation(int line, int row, int width, int space)
        {
            return new Point((line + 1) * width + (line - 1) * space, row * width + (row) * space);
        }
        private void choseLibrary(string libraryId)
        {
            Form form = new Seating_Chose_Form(libraryId);
            form.Show();

        }

        private void Library_Chose_Form_Load(object sender, EventArgs e)
        {
            Tb_LibraryManager manager = new Tb_LibraryManager();
            List<Tb_Library> list = manager.GetList();


            int line = 0;
            int row = 0;
            int width = 200;

            Color color = Color.FromArgb(192, 192, 0);
            Color bgColor = Color.FromName("LightGreen");
            Font font = new Font("宋体", 15);

            int space = 50;

            int lineCount = 2;
            for (int num = 0; num < list.Count; num++)
            {
                row = num / lineCount;
                ;
                line = num % lineCount;

                Button btn = buildNewLibrary(list[num].Name, line, row, width, ref color, ref bgColor, font, list[num].LibraryId, space);
                panel_library_box.Controls.Add(btn);


            }
        }

    }
}
